package com.zbkj.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.zbkj.admin.service.AdminEstimateAiHandleService;
import com.zbkj.admin.service.AdminProjectHandleService;
import com.zbkj.common.constants.Constants;
import com.zbkj.common.enums.CommonStatusEnum;
import com.zbkj.common.enums.InformationTypEnum;
import com.zbkj.common.enums.ProjectStatusEnum;
import com.zbkj.common.enums.ReportApplyStatusEnum;
import com.zbkj.common.exception.CommonException;
import com.zbkj.common.exception.ExceptionCodeEnum;
import com.zbkj.common.exception.ResultException;
import com.zbkj.common.model.project.*;
import com.zbkj.common.model.system.SystemAdmin;
import com.zbkj.common.oss.OssClientUtil;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.project.*;
import com.zbkj.common.response.UploadResponse;
import com.zbkj.common.response.project.AdminProjectInfoResponse;
import com.zbkj.common.response.project.InformationResponse;
import com.zbkj.common.response.project.ProjectStatusCountResponse;
import com.zbkj.common.response.project.ReportInfoResponse;
import com.zbkj.common.utils.CommonUtil;
import com.zbkj.common.vo.project.ProjectModifyConditionVo;
import com.zbkj.common.vo.project.ProjectQueryVo;
import com.zbkj.service.service.UploadService;
import com.zbkj.service.service.project.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Auther:
 * @Date: 2024/7/6 22:01
 * @Description:
 */
@Slf4j
//@Service
public class AdminProjectHandleServiceImpl implements AdminProjectHandleService {
   /* @Autowired
    private ProjectInfoService projectInfoService;
    @Autowired
    private UploadService uploadService;
    @Autowired
    private ProjectInformationService projectInformationService;
    @Autowired
    private EstimateInformationService estimateInformationService;
    @Autowired
    private ProjectReportService projectReportService;
    @Autowired
    private ProjectReportItemService projectReportItemService;
    @Autowired
    private OssClientUtil ossClientUtil;
    @Autowired
    private ReportApplyAuditService reportApplyAuditService;
    @Autowired
    private EstimateAiService estimateAiService;

    @Autowired
    @Lazy
    private AdminEstimateAiHandleService adminEstimateAiHandleService;

    @Override
    public UploadResponse informationUpload(Integer type, MultipartFile multipartFile) {
        if(!InformationTypEnum.adminTypeCheck(type)) {
            throw new CommonException("文件类型参数错误");
        }
        if(multipartFile == null || multipartFile.isEmpty()) {
            throw new CommonException("上传文件不能为空");
        }
        UploadResponse uploadResponse = new UploadResponse();
        uploadResponse.setFileName(multipartFile.getOriginalFilename());
        String fileType = FilenameUtils.getExtension(uploadResponse.getFileName());
        if(!CommonUtil.fileTypeCheck(Constants.ADMIN_FILE_TYPES,fileType)) {
            throw new CommonException("上传文件类型错误");
        }
        uploadResponse.setExtName(fileType);
        uploadResponse.setFileSize(multipartFile.getSize());
        String fileUrl =  uploadService.informationUpload(fileType, multipartFile);
        uploadResponse.setUrl(fileUrl);
        return uploadResponse;
    }

    @Override
    public PageInfo<AdminProjectInfoResponse> projectList(AdminProjectQueryRequest queryRequest) {
        ProjectQueryVo queryVo = new ProjectQueryVo();
        if(Objects.nonNull(queryRequest.getQueryStatus())) {
            queryVo.setStatusList(Lists.newArrayList(queryRequest.getQueryStatus()));
        }
        //queryVo.setRemindFlag(queryRequest.getRemindFlag());
        queryVo.setKeyword(queryRequest.getKeyword());
        queryVo.setStatusSort(queryRequest.getQueryStatus());
        queryVo.setSource(0);
        //分页查询项目列表
        PageInfo<ProjectInfo> projectPage = projectInfoService.projectList(queryVo,queryRequest.getPage(),queryRequest.getLimit());
        List<AdminProjectInfoResponse> responseList = Lists.newArrayList();
        for(ProjectInfo projectInfo : projectPage.getList()) {
            AdminProjectInfoResponse response = new AdminProjectInfoResponse();
            BeanUtils.copyProperties(projectInfo, response);
            responseList.add(response);
        }
        return CommonPage.copyPageInfo(projectPage, responseList);
    }

    @Override
    public ProjectStatusCountResponse getProjectStatusCount() {
        ProjectStatusCountResponse response = new ProjectStatusCountResponse();
        response.setRemindCount(projectInfoService.getProjectStatusCount(Lists.newArrayList(ProjectStatusEnum.TO_ESTIMATE.getStatus()),1,null));
        return response;
    }

    @Override
    public void withdrawProject(Long projectId) {
        ProjectInfo projectInfo = this.getProjectAndCheck(projectId);
        if(ProjectStatusEnum.isWithdrawn(projectInfo.getStatus())
                || ProjectStatusEnum.isCompletEstimate(projectInfo.getStatus())
                || ProjectStatusEnum.isInReport(projectInfo.getStatus())
                || ProjectStatusEnum.isFinish(projectInfo.getStatus())){
            throw new CommonException("项目状态已变更，不能强制撤回");
        }
        ProjectInfo updateProject = new ProjectInfo();
        updateProject.setId(projectInfo.getId());
        //撤回操作-项目属性设置为初始化状态
        projectInfoService.withdrawnAttrInit(updateProject);
        ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
        conditionVo.setNeStatusList(Lists.newArrayList(ProjectStatusEnum.WITHDRAWN.getStatus(),
                ProjectStatusEnum.COMPLET_ESTIMATE.getStatus(),ProjectStatusEnum.IN_REPORT.getStatus(),
                ProjectStatusEnum.FINISH.getStatus()));
        //更新项目信息
        boolean flag = projectInfoService.updateProject(updateProject,conditionVo);
        if(!flag) {
            throw new CommonException("项目已变更，请刷新后重试");
        }
    }

    @Override
    public void forceEstimateStart(Long projectId) {
        ProjectInfo projectInfo = this.getProjectAndCheck(projectId);
        if(!ProjectStatusEnum.isToEstimate(projectInfo.getStatus())){
            throw new CommonException("项目状态已变更，不能强制开始估算");
        }
        ProjectInfo updateProject = new ProjectInfo();
        updateProject.setId(projectInfo.getId());
        updateProject.setStatus(ProjectStatusEnum.IN_ESTIMATE.getStatus());
        updateProject.setEstimateSource(2);
        updateProject.setEstimateBeginTime(new Date());
        ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
        conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.TO_ESTIMATE.getStatus()));
        //更新项目信息
        boolean flag = projectInfoService.updateProject(updateProject,conditionVo);
        if(!flag) {
            throw new CommonException("项目已变更，请刷新后重试");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void informationSave(AdminInfomationRequest infomationRequest, SystemAdmin systemAdmin) {
        Long projectId = infomationRequest.getProjectId();
        ProjectInfo projectInfo = this.getProjectAndCheck(projectId);
        Integer requestFileType = infomationRequest.getFileType();
        //InformationTypEnum.typeCheck(requestFileType, InformationTypEnum.TYPE40.getType()) ||
        if(InformationTypEnum.typeCheck(requestFileType, InformationTypEnum.TYPE39.getType())) {
         //39、采购明细文件，40、功能明细文件
        } else if(InformationTypEnum.typeCheck(requestFileType, InformationTypEnum.TYPE42.getType())) {
            //42、手工估算结果文件  需更新项目 估算时间和估算确认标识为1  --0909修改-无手工估算文件上传
            *//*ProjectInfo updateProject = new ProjectInfo();
            updateProject.setId(projectInfo.getId());
            updateProject.setEstimateEndTime(new Date());
            updateProject.setEstimateFlag(1);
            ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
            conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.IN_ESTIMATE.getStatus()));
            //更新项目信息
            boolean flag = projectInfoService.updateProject(updateProject,conditionVo);
            if(!flag) {
                throw new CommonException("项目已变更，请刷新后重试");
            }*//*
            throw new CommonException("资料类型参数错误");
        } else if(InformationTypEnum.typeCheck(requestFileType, InformationTypEnum.TYPE43.getType())){
            ProjectInfo updateProject = new ProjectInfo();
            updateProject.setId(projectInfo.getId());
            updateProject.setReportTime(new Date());
            updateProject.setReportFlag(1);
            ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
            conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.IN_REPORT.getStatus()));
            //更新项目信息
            boolean flag = projectInfoService.updateProject(updateProject,conditionVo);
            if(!flag) {
                throw new CommonException("项目已变更，请刷新后重试");
            }
        } else {
            throw new CommonException("资料类型参数错误");
        }
        //保存上传文件记录
        estimateInformationService.informationSaveProcess(infomationRequest,systemAdmin.getId().longValue());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void reportApplyAudit(AdminReportApplyAuditRequest auditRequest, SystemAdmin systemAdmin) {
        ProjectInfo projectInfo = this.getProjectAndCheck(auditRequest.getProjectId());
        if(!ReportApplyStatusEnum.isInStatus(projectInfo.getReportApplyStatus())) {
            throw new CommonException("报告申请状态已变更");
        }
        ProjectInfo updateProject = new ProjectInfo();
        updateProject.setId(projectInfo.getId());
        ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
        conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.COMPLET_ESTIMATE.getStatus()));
        conditionVo.setReportApplyStatusList(Lists.newArrayList(ReportApplyStatusEnum.IN_APPLY.getStatus()));
        ReportApplyAudit reportApplyAudit = null;
        if(ReportApplyStatusEnum.isRejectStatus(auditRequest.getStatus())) {
            //申请驳回处理
            if(StringUtils.isBlank(auditRequest.getRejectReason())) {
                throw new CommonException("请填写驳回原因");
            }
            updateProject.setReportApplyStatus(ReportApplyStatusEnum.REJECT_APPLY.getStatus());
            //驳回审记录
            reportApplyAudit = new ReportApplyAudit();
            reportApplyAudit.setProjectId(auditRequest.getProjectId());
            reportApplyAudit.setRejectReason(auditRequest.getRejectReason());
            reportApplyAudit.setCreateId(systemAdmin.getId().longValue());
        } else if(ReportApplyStatusEnum.isPassStatus(auditRequest.getStatus())) {
            //申请通过处理
            updateProject.setReportApplyStatus(ReportApplyStatusEnum.PASS_APPLY.getStatus());
            updateProject.setReportStartTime(new Date());
            updateProject.setStatus(ProjectStatusEnum.IN_REPORT.getStatus());
        } else {
            throw new CommonException("审核状态参数错误");
        }
        //更新项目信息
        boolean flag = projectInfoService.updateProject(updateProject,conditionVo);
        if(!flag) {
            throw new CommonException("项目已变更，请刷新后重试");
        }
        if(Objects.nonNull(reportApplyAudit)) {
            //保存驳回原因记录
            reportApplyAuditService.save(reportApplyAudit);
        }
    }

    @Override
    public List<ReportApplyAudit> getReportApplyAuditList(Long projectId) {
        List<ReportApplyAudit> list = reportApplyAuditService.getListByProjectId(projectId);
        for (ReportApplyAudit pojo : list) {
            pojo.setCreatePhone(CommonUtil.maskMobile(pojo.getCreatePhone()));
        }
        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void projectReportSave(AdminReportRequest reportRequest,SystemAdmin systemAdmin) {
        ProjectInfo projectInfo = this.getProjectAndCheck(reportRequest.getProjectId());
        if(!ProjectStatusEnum.estimateSubmitCheck(projectInfo.getStatus())) {
            throw new CommonException("项目状态已变更，无法提交保存");
        }
        //新增|编辑估算总结内容
        projectReportService.saveOrUpdateReport(reportRequest);
        //保存提交估算总结明细（先逻辑删除旧记录，在进行保存）
        projectReportItemService.saveProcess(reportRequest.getProjectId(),reportRequest.getItemRequestList());
        //保存功能点明细文件记录
        AdminInfomationRequest infomationRequest = new AdminInfomationRequest();
        infomationRequest.setProjectId(reportRequest.getProjectId());
        infomationRequest.setFileType(InformationTypEnum.TYPE40.getType());
        infomationRequest.setFileName(reportRequest.getFileName());
        infomationRequest.setFilePath(reportRequest.getFilePath());
        //保存上传报告文件记录
        estimateInformationService.informationSaveProcess(infomationRequest,systemAdmin.getId().longValue());
    }

    public ReportInfoResponse getReportToEdit(Long projectId) {
        ProjectInfo project = this.getProjectAndCheck(projectId);
        if(!ProjectStatusEnum.estimateSubmitCheck(project.getStatus())) {
            throw new CommonException("项目状态已变更，无法获取项目报告");
        }
        ReportInfoResponse response = new ReportInfoResponse();
        response.setProjectId(project.getId());
        response.setProjectName(project.getProjectName());
        //估算结果填写内容信息
        ProjectReport reportDb = projectReportService.getByProjectId(projectId);
        if(Objects.nonNull(reportDb)) {
            ReportInfoResponse.InfoResponse infoResponse = new ReportInfoResponse.InfoResponse();
            BeanUtils.copyProperties(reportDb,infoResponse);
            //获取估算结果明细项集合
            List<ProjectReportItem> itemDbList = projectReportItemService.getItemsByProjectId(projectId);
            List<ReportInfoResponse.ItemResponse> itemResponseList = Lists.newArrayList();
            for (ProjectReportItem itemDb : itemDbList) {
                ReportInfoResponse.ItemResponse itemResponse = new ReportInfoResponse.ItemResponse();
                BeanUtils.copyProperties(itemDb,itemResponse);
                itemResponseList.add(itemResponse);
            }
            response.setItemList(itemResponseList);
            response.setInfoResponse(infoResponse);

            //获取当前有效功能明细上传记录
            EstimateInformation information = estimateInformationService.getOneRecord(null, projectId, InformationTypEnum.TYPE40.getType(), CommonStatusEnum.VALID_STATUS.getStatus());
            if(Objects.nonNull(information)) {
                InformationResponse informationResponse = new InformationResponse();
                BeanUtils.copyProperties(information,informationResponse);
                informationResponse.setFilePath(ossClientUtil.addDomain(informationResponse.getFilePath()));
                response.setInformationResponse(informationResponse);
            }
        }
        return response;
    }

    @Override
    public ReportInfoResponse getReportInfo(Long projectId) {
        ProjectInfo project = this.getProjectAndCheck(projectId);
        *//*if(!ProjectStatusEnum.isInReport(project.getStatus()) && !ProjectStatusEnum.isFinish(project.getStatus())) {
            throw new CommonException("项目状态已变更，无法获取项目报告");
        }*//*
        if(!ProjectStatusEnum.estimateSubmitCheck(project.getStatus())) {
            throw new CommonException("项目状态已变更，无法获取项目报告");
        }
        //项目基本信息赋值
        ReportInfoResponse response = new ReportInfoResponse();
        response.setProjectId(project.getId());
        response.setProjectName(project.getProjectName());
        response.setBudgetAmount(project.getBudgetAmount());
        response.setCreateTime(project.getCreateTime());
        if(ProjectStatusEnum.isFinish(project.getStatus())) {
            response.setEndTime(project.getCompleteTime());
        } else {
            response.setEndTime(project.getEstimateConfirmTime());
        }
        //估算结果填写内容信息
        ProjectReport reportDb = projectReportService.getByProjectId(projectId);
        if(Objects.nonNull(reportDb)) {
            ReportInfoResponse.InfoResponse infoResponse = new ReportInfoResponse.InfoResponse();
            BeanUtils.copyProperties(reportDb,infoResponse);
            //获取估算结果明细项集合
            List<ProjectReportItem> itemDbList = projectReportItemService.getItemsByProjectId(projectId);
            List<ReportInfoResponse.ItemResponse> itemResponseList = Lists.newArrayList();
            BigDecimal totalFactor = BigDecimal.ZERO;
            for (ProjectReportItem itemDb : itemDbList) {
                ReportInfoResponse.ItemResponse itemResponse = new ReportInfoResponse.ItemResponse();
                BeanUtils.copyProperties(itemDb,itemResponse);
                itemResponseList.add(itemResponse);
                totalFactor = totalFactor.add(itemDb.getAdjustFactor());
            }
            response.setItemList(itemResponseList);
            infoResponse.setTotalFactor(totalFactor);
            response.setInfoResponse(infoResponse);
        }
        return response;
    }

    @Override
    public PageInfo<InformationResponse> getInformationList(InformationQueryRequest queryRequest) {
        PageInfo<EstimateInformation> pageInfo = estimateInformationService.getInformationList(queryRequest);
        List<EstimateInformation> dbList = pageInfo.getList();
        List<InformationResponse> responseList = Lists.newArrayList();
        for (EstimateInformation pojo : dbList) {
            InformationResponse vo = new InformationResponse();
            BeanUtils.copyProperties(pojo, vo);
            vo.setFilePath(ossClientUtil.addDomain(vo.getFilePath()));
            vo.setCreatePhone(CommonUtil.maskMobile(vo.getCreatePhone()));
            responseList.add(vo);
        }
        return CommonPage.copyPageInfo(pageInfo,responseList);
    }

    @Override
    public List<InformationResponse> getValidProjectFileList(Long projectId) {
        ProjectInfo projectInfo = this.getProjectAndCheck(projectId);
        if(ProjectStatusEnum.isWithdrawn(projectInfo.getStatus())) {
            throw new ResultException(ExceptionCodeEnum.PROJECT_STATUS_ERROR);
        }
        List<ProjectInformation> dbList = projectInformationService.getValidProjectInformationList(projectId);
        List<InformationResponse> responseList = Lists.newArrayList();
        for(ProjectInformation pojo : dbList) {
            InformationResponse vo = new InformationResponse();
            BeanUtils.copyProperties(pojo, vo);
            vo.setFilePath(ossClientUtil.addDomain(vo.getFilePath()));
            //vo.setCreatePhone(CommonUtil.maskMobile(vo.getCreatePhone()));
            responseList.add(vo);
        }
        return responseList;
    }

    @Override
    public InformationResponse getValidInformation(Long projectId, Integer type) {
        EstimateInformation information = estimateInformationService.getOneRecord(null, projectId, type, CommonStatusEnum.VALID_STATUS.getStatus());
        if(Objects.isNull(information)) {
            throw new CommonException("项目资料还未生成，请稍后再试");
        }
        InformationResponse response = new InformationResponse();
        BeanUtils.copyProperties(information,response);
        response.setFilePath(ossClientUtil.addDomain(response.getFilePath()));
        return response;
    }

    @Override
    public void unLockProject(Long projectId) {
        boolean flag = projectInfoService.projectLockUpdate(projectId,0);
        if(!flag) {
            throw new CommonException("项目已变更，请刷新后重试");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void aiContentSubmit(AdminAiContentRequest contentRequest, SystemAdmin systemAdmin) {
        ProjectInfo projectInfo = this.getProjectAndCheck(contentRequest.getProjectId());
        if(!ProjectStatusEnum.isToEstimate(projectInfo.getStatus())) {
            throw new CommonException("项目状态已变更，请刷新后重试");
        }
        List<EstimateAi> estimateAiList = Lists.newArrayList();
        List<String> contentList = Lists.newArrayList();

        String aiReqNo = CommonUtil.getRandomStr("");
        for(AdminAiContentRequest.ContentRequest content : contentRequest.getContentList()) {
            EstimateAi eai = new EstimateAi();
            BeanUtils.copyProperties(content,eai);
            eai.setProjectId(projectInfo.getId());
            eai.setCreateId(systemAdmin.getId().longValue());
            eai.setReqNo(aiReqNo);
            estimateAiList.add(eai);
            contentList.add(content.getContent());
        }
        if(CollectionUtils.isNotEmpty(estimateAiList)) {
            ProjectInfo updateProject = new ProjectInfo();
            updateProject.setId(projectInfo.getId());
            updateProject.setStatus(ProjectStatusEnum.IN_ESTIMATE.getStatus());
            updateProject.setEstimateSource(1);
            updateProject.setEstimateBeginTime(new Date());
            ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
            conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.TO_ESTIMATE.getStatus()));
            //更新项目信息
            boolean flag = projectInfoService.updateProject(updateProject,conditionVo);
            if(!flag) {
                throw new CommonException("项目已变更，请刷新后重试");
            }
            //删除原有内容记录
            estimateAiService.delByProjectId(projectInfo.getId());
            estimateAiService.saveBatch(estimateAiList,estimateAiList.size());
            //调用AI接口--
            *//*AiEstimateRequest aiRequest = new AiEstimateRequest();
            aiRequest.setReqNo(aiReqNo);
            aiRequest.setProjectId(projectInfo.getId());
            aiRequest.setProjectName(projectInfo.getProjectName());
            aiRequest.setProjectType(projectInfo.getProjectType());
            //组装ai请求需求拆分内容对象
            this.qiContentReqBuild(aiRequest,estimateAiList);
            adminEstimateAiHandleService.estimateStartAiRequest(aiRequest);*//*
        } else {
            throw new CommonException("缺少内容记录");
        }

    }

    @Override
    public List<EstimateAi> aiContentList(Long projectId) {
        return estimateAiService.getAiContentList(projectId);
    }

    @Override
    public ProjectInfo getProjectAndCheck(Long projectId) {
        ProjectInfo projectInfo = projectInfoService.getById(projectId);
        if(Objects.isNull(projectInfo) || projectInfo.getDeleteFlag() != 0) {
            throw new CommonException("项目信息不存在");
        }
        if(ProjectStatusEnum.isWithdrawn(projectInfo.getStatus())) {
            throw new CommonException("项目已被撤回");
        }
        return projectInfo;
    }

    @Override
    public AdminProjectInfoResponse getProjectInfo(Long projectId) {
        ProjectInfo projectInfo = this.getProjectAndCheck(projectId);
        AdminProjectInfoResponse response = new AdminProjectInfoResponse();
        BeanUtils.copyProperties(projectInfo,response);
        return response;
    }

    @Override
    public PageInfo<InformationResponse> getProjectFileList(ProjectFileQueryRequest queryRequest) {
        LambdaQueryWrapper<ProjectInformation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProjectInformation::getDeleteFlag, 0)
                .eq(ProjectInformation::getProjectId, queryRequest.getProjectId());
        if(StringUtils.isNotBlank(queryRequest.getBeginDate())) {
            queryWrapper.ge(ProjectInformation::getCreateTime, queryRequest.getBeginDate());
        }
        if(StringUtils.isNotBlank(queryRequest.getEndDate())) {
            queryWrapper.le(ProjectInformation::getCreateTime, queryRequest.getEndDate());
        }
        queryWrapper.orderByDesc(ProjectInformation::getCreateTime);
        Page<ProjectInformation> pageObj = PageHelper.startPage(queryRequest.getPage(), queryRequest.getLimit());
        List<ProjectInformation> projectInformationList = projectInformationService.list(queryWrapper);
        List<InformationResponse> responseList = Lists.newArrayList();
        for(ProjectInformation pojo : projectInformationList) {
            InformationResponse vo = new InformationResponse();
            BeanUtils.copyProperties(pojo, vo);
            vo.setFilePath(ossClientUtil.addDomain(vo.getFilePath()));
            //vo.setCreatePhone(CommonUtil.maskMobile(vo.getCreatePhone()));
            responseList.add(vo);
        }
        return CommonPage.copyPageInfo(pageObj,responseList);
    }

    @Override
    public void estimaNotifyClient(AdminEstimaNotifyClientRequest esNotifyRequest) {
        ProjectInfo projectInfo = this.getProjectAndCheck(esNotifyRequest.getProjectId());
        if(!ProjectStatusEnum.estimateSubmitCheck(projectInfo.getStatus())) {
            throw new CommonException("项目状态已变更，请刷新后重试");
        }
        ProjectInfo updateProject = new ProjectInfo();
        updateProject.setId(projectInfo.getId());
        if(projectInfo.getEstimateFlag().intValue() != 1) {
            updateProject.setEstimateEndTime(new Date());
        }
        updateProject.setEstimateFlag(1);
        ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
        conditionVo.setNeStatusList(Lists.newArrayList(ProjectStatusEnum.TO_ESTIMATE.getStatus(),ProjectStatusEnum.WITHDRAWN.getStatus()));
        //更新项目信息
        boolean flag = projectInfoService.updateProject(updateProject,conditionVo);
        if(!flag) {
            throw new CommonException("项目已变更，请刷新后重试");
        }

    }

    *//**
     * 组装ai请求需求拆分内容对象
     * @param aiRequest
     * @param estimateList
     *//*
    private void qiContentReqBuild(AiEstimateRequest aiRequest,List<EstimateAi> estimateList) {
        Map<String,List<EstimateAi>> titleGroupMap = estimateList.stream().collect(Collectors.groupingBy(k->k.getTitle()));
        Map<String,Integer> titlSortMap = estimateList.stream().collect(Collectors.toMap(k->k.getTitle(),v->v.getTitleSort(),(ov,nv)->ov));
        List<AiEstimateRequest.AiTileRequest> tileReqList = Lists.newArrayList();
        titlSortMap.forEach((key,val)->{
            AiEstimateRequest.AiTileRequest titleReq = new AiEstimateRequest.AiTileRequest();
            titleReq.setTitle(key);
            titleReq.setTitleNum(val);
            List<EstimateAi> tempList = titleGroupMap.getOrDefault(key,Lists.newArrayList());
            List<AiEstimateRequest.AiContentRequest> contentReqList = Lists.newArrayList();
            for(EstimateAi ai : tempList) {
                AiEstimateRequest.AiContentRequest aiContentReq = new AiEstimateRequest.AiContentRequest();
                aiContentReq.setContent(ai.getContent());
                aiContentReq.setSortNum(ai.getSortNum());
                contentReqList.add(aiContentReq);
            }
            //titleReq.setContentList(contentReqList.stream().sorted(Comparator.comparing(c->c.getSortNum())).collect(Collectors.toList()));
            titleReq.setContentList(contentReqList);
            tileReqList.add(titleReq);
        });
        //aiRequest.setContentList(tileReqList.stream().sorted(Comparator.comparing(t->t.getTitleNum())).collect(Collectors.toList()));
        aiRequest.setContentList(tileReqList);
    }*/
}
